<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>用户搜索 - 权限管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
</head>
<body>
<div class="header">
    <div class="nav">
        <div class="nav-brand">权限管理系统</div>
        <ul class="nav-links">
            <li><a href="${pageContext.request.contextPath}/">首页</a></li>
            <li><a href="${pageContext.request.contextPath}/user/list">用户管理</a></li>
            <li><a href="${pageContext.request.contextPath}/role/list">角色管理</a></li>
            <li><a href="${pageContext.request.contextPath}/user/search">用户搜索</a></li>
        </ul>
    </div>
</div>

<div class="container">
    <div class="card">
        <h2>用户搜索</h2>

        <form method="get" class="search-form">
            <div class="form-group">
                <label>用户名</label>
                <input type="text" name="username" value="${param.username}"
                       class="form-control" placeholder="输入用户名">
            </div>
            <div class="form-group">
                <label>邮箱</label>
                <input type="text" name="email" value="${param.email}"
                       class="form-control" placeholder="输入邮箱">
            </div>
            <div class="form-group">
                <label>状态</label>
                <select name="status" class="form-control">
                    <option value="">全部</option>
                    <option value="0" ${param.status == '0' ? 'selected' : ''}>正常</option>
                    <option value="1" ${param.status == '1' ? 'selected' : ''}>禁用</option>
                </select>
            </div>
            <div class="form-group">
                <label>&nbsp;</label>
                <button type="submit" class="btn btn-primary">搜索</button>
            </div>
        </form>

        <c:if test="${not empty users}">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>登录名</th>
                    <th>姓名</th>
                    <th>邮箱</th>
                    <th>状态</th>
                    <th>角色</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="user" items="${users}">
                    <tr>
                        <td>${user.id}</td>
                        <td>${user.loginname}</td>
                        <td>${user.name}</td>
                        <td>${user.email}</td>
                        <td>
                                    <span class="badge ${user.status == 0 ? 'badge-success' : 'badge-danger'}">
                                            ${user.status == 0 ? '正常' : '禁用'}
                                    </span>
                        </td>
                        <td>
                            <div class="role-list">
                                <c:forEach var="role" items="${user.roles}">
                                    <span class="role-item">${role.name}</span>
                                </c:forEach>
                                <c:if test="${empty user.roles}">
                                    <span>无角色</span>
                                </c:if>
                            </div>
                        </td>
                        <td>
                            <a href="${pageContext.request.contextPath}/user/detail?username=${user.loginname}"
                               class="btn btn-primary">详情</a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </c:if>

        <c:if test="${empty users}">
            <p>没有找到符合条件的用户</p>
        </c:if>
    </div>
</div>
</body>
</html>